package com.lanren;

import com.lanren.utils.GsonUtils;

import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;

public class GsonTest {

    public static void main(String[] args) {
        String json = "{\"resultCode\":\"SUCCESS\",\"resultDesc\":\"SUCCESS\",\"userProfile\":{\"userId\":\"901228507\",\"registTime\":\"20180622161442\",\"accounts\":[{\"accountName\":\"123566965\",\"accoutType\":\"MOBILE\",\"bindTime\":null,\"verified\":false,\"accountExtInfo\":null}],\"avatar\":null,\"nickName\":null,\"userRole\":null,\"usernum\":null,\"extInfo\":null}}";

//        System.out.println("有斜杠 =" + json);

       /* List<Map<String, String>> list = new ArrayList<Map<String, String>>();

        for (int i = 0; i < 10; i++) {
            HashMap<String, String> map = new HashMap<String, String>();
            map.put("invite", "han" + i);
            list.add(map);
        }

        System.out.println(GsonUtils.toJson(list));

        JsonArray jsonArray = GsonUtils.getJsonArray(GsonUtils.toJson(list));
        for (JsonElement jsonElement : jsonArray) {
            System.out.println(jsonElement.getAsJsonObject().get("invite"));
        }

        System.out.println("hans=" + GsonUtils.fromJsonToListMaps(GsonUtils.toJson(jsonArray)));

        List<Map<String, String>> hanList = GsonUtils.fromJsonToListMaps(GsonUtils.toJson(jsonArray));

        for (int i = 0; i < hanList.size(); i++) {
            String nnn = hanList.get(i).get("invite");
            if (nnn.equals("han1")) {
                hanList.get(i).remove("invite");//删除
                hanList.remove(i);//删除list 数据和内存
            }
//            hanList.get(i).put("invite", "han" + (i + 1));//修改
        }
        System.out.println("hans11=" + GsonUtils.toJson(hanList));
        JsonObject root = GsonUtils.getJsonObject(json);
//        System.out.println(root);
        for (Map.Entry<String, JsonElement> e : root.entrySet()) {
//            System.out.println("key:" + e.getKey());
//            System.out.println("value:" + e.getValue());
        }*/

//        List<Map<String, String>> lists = new ArrayList<Map<String, String>>();
//        HashMap<String, String> map = new HashMap<String, String>();
//        map.put("member", "han");
//        lists.add(map);
//        HashMap<String, String> map1 = new HashMap<String, String>();
//        map1.put("member", "han1");
//        lists.add(map1);
//        HashMap<String, String> map2 = new HashMap<String, String>();
//        map2.put("bookName", "日常");
//        map2.put("members", GsonUtils.toJson(lists));
//        System.out.println("hans11=" + GsonUtils.toJson(map2));

//
//        String msg = "上海地铁乘车扣款";
//        System.out.println(msg.contains("1"));

//        List<Map<String, String>> bookCreateList = new ArrayList<Map<String, String>>();
//        HashMap<String, String> map1 = new HashMap<String, String>();
//        map1.put("userInvite", "hengsan");
//        bookCreateList.add(map1);
//        HashMap<String, String> map2 = new HashMap<String, String>();
//        map2.put("userInvite", "hss");
//        bookCreateList.add(map2);
//
//        HashMap<String, String> map3 = new HashMap<String, String>();
//        map3.put("bookId", "1");
//        map3.put("bookName", "日常1");
//        map3.put("budget", "2001");
//        map3.put("invite", GsonUtils.toJson(bookCreateList));
//
//        System.out.println("hans11=" + GsonUtils.toJson(map3));

        LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
        map.put("id","1");
        map.put("bookTime","2019-10-2 17:45");
        map.put("object","zzz");
        map.put("inOut","支出");
        map.put("goods","烧饼");
        map.put("ps","烧饼zzz");
        map.put("money","8.0");
        map.put("paymentType","支付宝");
        map.put("bookSubmitUser","hengsan");
        map.put("bookMember","han");
        map.put("bookClassify","餐饮");
        map.put("createBookId","1");
        System.out.println("hans11=" + GsonUtils.toJson(map));
    }
}
